/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft YaHei', Arial, sans-serif;
    background: #f5f5f5;
}

.container {
    min-height: 100vh;
    color: #fff;
    padding: 15px;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.background-image {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -2;
    object-fit: cover;
}

.background-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: -1;
}

.header {
    text-align: center;
    margin-bottom: 20px;
    padding: 0 10px;
}

.title {
    display: block;
    font-size: clamp(18px, 5vw, 22px);
    font-weight: bold;
    margin-bottom: 5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    color: #fff;
}

.preview-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 25px;
    padding: 0 10px;
}

.preview-title {
    font-size: clamp(16px, 4vw, 18px);
    margin-bottom: 15px;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* 修改后的容器样式 - 固定比例但响应式缩放 */
.canvas-container {
    /* 使用视口单位实现响应式缩放 */
    width: min(60vw, 50vh, 320px);
    height: min(60vw, 50vh, 320px);
    /* 保持正方形 */
    aspect-ratio: 1/1;
    overflow: hidden;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    margin-bottom: 20px;
    background: #2c3e50;
    border-radius: 10px;
    border: 3px solid #fff;
    /* 添加过渡效果 */
    transition: all 0.3s ease;
}

.avatar-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.action-buttons {
    display: flex;
    gap: 15px;
    width: 100%;
    max-width: min(90vw, 300px);
    justify-content: center;
}

.btn {
    padding: clamp(10px, 2.5vw, 12px) clamp(20px, 5vw, 25px);
    border-radius: 30px;
    border: none;
    font-size: clamp(14px, 3.5vw, 16px);
    font-weight: bold;
    transition: all 0.3s ease;
    min-width: clamp(80px, 20vw, 100px);
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.save-btn {
    background: linear-gradient(135deg, #75809C, #5a647a);
    color: white;
}

.save-btn:hover {
    background: linear-gradient(135deg, #5a647a, #4a546b);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.reset-btn {
    background: linear-gradient(135deg, #976666, #795252);
    color: white;
}

.reset-btn:hover {
    background: linear-gradient(135deg, #795252, #6a4545);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.upload-section {
    margin-top: 30px;
    margin-bottom: 20px;
    padding: 0 10px;
    width: 100%;
    max-width: min(90vw, 400px);
}

.upload-btn {
    width: 100%;
    background: linear-gradient(135deg, #4d6085, #3d4d6a);
    color: white;
    padding: clamp(12px, 3vw, 15px);
    border-radius: 30px;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
    border: none;
    cursor: pointer;
    font-size: clamp(14px, 3.5vw, 16px);
    font-weight: bold;
    transition: all 0.3s ease;
}

.upload-btn:hover {
    background: linear-gradient(135deg, #3d4d6a, #2d3a50);
    transform: translateY(-2px);
}

/* 关键修改：让选择区域左对齐 */
.avatar_choose {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* 改为左对齐 */
    padding: 0 10px;
    width: 100%;
    max-width: min(95vw, 800px); /* 限制最大宽度 */
}

.section-header {
    margin-bottom: 12px;
    padding: 0;
    width: 100%;
}

.section-title {
    display: block;
    font-size: clamp(14px, 3.5vw, 16px);
    font-weight: bold;
    color: white;
    text-align: left;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.avatar-scroll, .frame-scroll {
    width: 100%;
    height: clamp(70px, 15vh, 90px);
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0;
}

.avatar-list, .frame-list {
    display: flex;
    flex-direction: row;
    height: 100%;
    align-items: center;
    gap: 12px;
}

.avatar-item {
    width: clamp(60px, 12vw, 70px);
    height: clamp(60px, 12vw, 70px);
    flex-shrink: 0;
    border: 2px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
    background: #34495e;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.avatar-item:hover {
    transform: scale(0.95);
    border-color: #3498db;
}

.avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.default-avatars, .frame-section {
    margin-bottom: 25px;
    width: 100%;
}

.frame-item {
    width: clamp(70px, 14vw, 80px);
    height: clamp(70px, 14vw, 80px);
    flex-shrink: 0;
    border: 2px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
    background: #34495e;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.frame-item.active {
    border-color: #e74c3c;
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(231, 76, 60, 0.4);
}

.frame-item:hover:not(.active) {
    transform: scale(0.95);
    border-color: #3498db;
}

.frame-preview {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    object-fit: cover;
}

.frame-text {
    color: white;
    font-size: clamp(12px, 2.5vw, 14px);
    font-weight: bold;
}

.tips {
    padding: 15px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    margin: 0 10px 20px;
    backdrop-filter: blur(10px);
    max-width: min(95vw, 800px);
    align-self: flex-start; /* 提示区域也左对齐 */
}

.tip-text {
    display: block;
    font-size: clamp(12px, 3vw, 14px);
    line-height: 1.6;
    margin-bottom: 8px;
    opacity: 0.9;
}

.avatar-list {
    min-width: min-content;
}

.frame-list {
    display: grid;
    grid-template-rows: 1fr 1fr;
    grid-template-columns: repeat(auto-fill, clamp(70px, 14vw, 80px));
    grid-auto-flow: column;
    gap: 12px;
    width: max-content;
    height: 100%;
}

/* 隐藏滚动条 */
.avatar-scroll::-webkit-scrollbar,
.frame-scroll::-webkit-scrollbar {
    display: none;
}

.avatar-scroll,
.frame-scroll {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.frame-scroll {
    width: 100%;
    height: clamp(140px, 30vh, 172px);
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0;
}

/* 增强的响应式设计 */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .canvas-container {
        width: min(70vw, 60vh, 280px);
        height: min(70vw, 60vh, 280px);
    }
    
    .avatar_choose {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 8px;
    }
    
    .canvas-container {
        width: min(80vw, 70vh, 240px);
        height: min(80vw, 70vh, 240px);
        border-width: 2px;
    }
    
    .action-buttons {
        gap: 10px;
    }
    
    .avatar_choose {
        padding: 0 5px;
    }
}

@media (max-width: 360px) {
    .canvas-container {
        width: min(85vw, 75vh, 200px);
        height: min(85vw, 75vh, 200px);
    }
}

/* 超大屏幕适配 */
@media (min-width: 1200px) {
    .container {
        max-width: 1200px;
    }
    
    .canvas-container {
        width: 320px;
        height: 320px;
    }
    
    .avatar_choose {
        max-width: 1000px;
    }
}

/* 添加平滑的缩放动画 */
@media (prefers-reduced-motion: no-preference) {
    .canvas-container {
        will-change: transform;
    }
}
